import 'package:flutter/material.dart';

import '../beans.dart';

class TodoListPage extends StatelessWidget{

  @override
  Widget build(BuildContext context) {
    return new MaterialApp(
      title: 'todolist',
      home: new Scaffold(
        appBar: new AppBar(
          title: new Text('todo list'),
        ),
        body: new SLT(new List<Todo>.generate(20, (index){
          return new Todo('title ${index+1}', 'desc ${index + 1}');
        })),
      ),
    );
  }
}

class SLT extends StatelessWidget {

  SLT(this.items);

  final List<Todo> items;

  @override
  Widget build(BuildContext context) {
    return new ListView.builder(
      itemBuilder: (context, index) {
        final item = items[index];
        return new ListTile(
          title: new Text(item.title),
          subtitle: new Text(item.description),
          leading: new Icon(Icons.table_chart, color: Colors.red,),
          onTap: (){
            Navigator.push(context,
                new MaterialPageRoute(builder: (context) => new TodoDetail(item)));
          },
        );
      },
      itemCount: items.length,
    );
  }
}

class TodoDetail extends StatelessWidget{

  final Todo todo;

  TodoDetail(this.todo);

  @override
  Widget build(BuildContext context) {
    return new MaterialApp(
      title: 'tododetail',
      home: new Scaffold(
        appBar: new AppBar(
          title: new Text('tododetail'),
        ),
        body: new Center(
          child: new Column(
            mainAxisAlignment: MainAxisAlignment.spaceEvenly,
            children: <Widget>[
              new Row(
                children: <Widget>[
                  new Text(todo.title, style: new TextStyle(
                    fontSize: 30.0,
                    fontWeight: FontWeight.bold,
                    color: Colors.black87
                  ),)
                ],
              ),
              new Row(
                children: <Widget>[
                  new Text(todo.description, style: new TextStyle(
                    fontSize: 13.0,
                    color: Colors.grey[350]
                  ),)
                ],
              ),
            ],
          ),
        ),
      ),
    );
  }
}
